package com.yanqu.road.server.manger.systemgroup.newmonopolymarket;

import com.google.protobuf.AbstractMessage;
import com.yanqu.road.dao.impl.nenmonopolymarket.NewMonopolyMarketReportDataDaoImpl;
import com.yanqu.road.entity.config.patrons.PatronsInfo;
import com.yanqu.road.entity.config.skill.SkillInfo;
import com.yanqu.road.entity.enums.eMailType;
import com.yanqu.road.entity.enums.eMonopolyMarketResType;
import com.yanqu.road.entity.enums.eSkillType;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.entity.log.newmonopolymarket.NewMonopolyMarketOfficeUserSeatLogData;
import com.yanqu.road.entity.log.newmonopolymarket.NewMonopolyMarketUserPhysicalChangeLogData;
import com.yanqu.road.entity.player.*;
import com.yanqu.road.entity.systemgroup.ResourceServerGroup;
import com.yanqu.road.entity.systemgroup.common.SystemServerGroupWeekData;
import com.yanqu.road.entity.systemgroup.newmonopolymarket.NewMonopolyMarketUserData;
import com.yanqu.road.entity.systemgroup.newmonopolymarket.config.NewMonopolyMarketResConfigData;
import com.yanqu.road.entity.systemgroup.newmonopolymarket.resgrab.NewMonopolyMarketReportData;
import com.yanqu.road.entity.systemgroup.newmonopolymarket.resgrab.NewMonopolyMarketResGrabDispatchInfo;
import com.yanqu.road.entity.systemgroup.newmonopolymarket.resgrab.NewMonopolyMarketResGrabMap;
import com.yanqu.road.entity.systemgroup.newmonopolymarket.resgrab.NewMonopolyMarketTempPoint;
import com.yanqu.road.logic.bussiness.monopolymarket.NewMonopolyMarketBussiness;
import com.yanqu.road.logic.bussiness.player.UserBeautyBussiness;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.common.CommonProto;
import com.yanqu.road.pb.newmonopolymkt.NewMonopolyMarketProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.newmonopolymkt.NewMonopolyMarketModule;
import com.yanqu.road.server.gameplayer.module.patrons.PatronsModule;
import com.yanqu.road.server.gameplayer.module.player.BeautyModule;
import com.yanqu.road.server.logic.mail.MailManager;
import com.yanqu.road.server.manger.ConfigMgr;
import com.yanqu.road.server.manger.MultipleLanguageMgr;
import com.yanqu.road.server.manger.NewMonopolyMarketCommonMgr;
import com.yanqu.road.server.manger.ServerListMgr;
import com.yanqu.road.server.manger.activity.curio.CurioMgr;
import com.yanqu.road.server.manger.config.PatronsMgr;
import com.yanqu.road.server.manger.config.SkillMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.server.manger.patrons.PatronsSimpleCacheMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.manger.systemgroup.CrossSystemGroupMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.config.Config;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;
import org.apache.mina.util.ConcurrentHashSet;

import java.math.BigInteger;
import java.text.MessageFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class NewMonopolyMarketMgr extends TempMgr {


    //资源点配表
    private static List<NewMonopolyMarketResConfigData> resConfigList = new ArrayList<>();

    //需要上传基本信息的玩家
    private static Set<Long> needUploadUserInfoSet = new ConcurrentHashSet<>();

    // 需要上传玩家派遣对象 k:userId k:资源类型 v 对象集合
    private static ConcurrentHashMap<Long, ConcurrentHashMap<Integer, Set<Integer>>> needUploadObjectInfoMap = new ConcurrentHashMap<>();

    /**
     * 当前分组资源争夺战地图信息
     * //groupId
     */
    public static Map<Integer, NewMonopolyMarketResGrabMap> resGrabMapMap = new HashMap<>();

    // weekId， 分组信息，定时同步
    private static Map<Integer, Map<Integer, ResourceServerGroup>> weekResourceGroupMap = new ConcurrentHashMap<>();

    public static ResourceServerGroup getInnerResourceServerGroup(int weekId, int resGroupId){
        if(!weekResourceGroupMap.containsKey(weekId)){
            return null;
        }
        return weekResourceGroupMap.get(weekId).get(resGroupId);
    }

    public static void syncInnerResourceServerGroup(int weekId, Map<Integer, ResourceServerGroup> groupMap){
        synchronized (weekResourceGroupMap){
            if(!weekResourceGroupMap.containsKey(weekId)){
                weekResourceGroupMap.put(weekId, new ConcurrentHashMap<>());
            }
            weekResourceGroupMap.get(weekId).putAll(groupMap);
        }
        initMap(weekId, groupMap);
    }

    private static void initMap(int weekId, Map<Integer, ResourceServerGroup> groupMap) {
        for (Map.Entry<Integer, ResourceServerGroup> entry : groupMap.entrySet()) {

        }
    }

    @Override
    public boolean save() {
        return true;
    }

    /**
     * 玩家是否能进入系统
     * @param player
     * @return
     */
    public static boolean canEnterSystem(GamePlayer player){
        if (!SystemOpenMgr.systemOpen(player, eSystemId.NewMonopolyMarket.getValue())) {
            // 系统未解锁
            return false;
        }
        return isSystemOpenTime();
    }

    /**
     * 判断系统是否开放
     * @return
     */
    public static boolean isSystemOpenTime(){
        int weekId = GameConfig.getSystemThisWeekId();
        SystemServerGroupWeekData groupWeekData = CrossSystemGroupMgr.getSystemServerGroup(weekId, eSystemId.NewMonopolyMarket.getValue());
        // 没有分组
        if(groupWeekData == null){
            return false;
        }
        return true;
    }

    /**
     * 判断系统是否开放
     * @return
     */
    public static boolean isSystemOpenTime(int type){
        int weekId = GameConfig.getSystemThisWeekId();
        SystemServerGroupWeekData groupWeekData = CrossSystemGroupMgr.getSystemServerGroup(weekId, eSystemId.NewMonopolyMarket.getValue());
        // 没有分组
        if(groupWeekData == null){
            return false;
        }
        return NewMonopolyMarketCommonMgr.isSystemOpenTime(type);
    }

    //刷新就刷新，重置就重置，搞啥呢(保证信息都同步了跨服的状态再来重置)
    public static void refreshUser(GamePlayer player ,boolean forceUpdate, boolean isSyn){
        // 刷新抢夺次数
        NewMonopolyMarketModule marketModule = player.getModule(NewMonopolyMarketModule.class);
        if(marketModule.userData == null){
            return;
        }
        int now = DateHelper.getCurrentSecond();
        synchronized (marketModule){
            if(!resetUser(marketModule)){
                refreshOfficeTeaReward(marketModule.userData, now);
                refreshGuanYin(marketModule.userData, now, forceUpdate);
                resetRobTimes(marketModule,now);
                resetResGrabDispatch(marketModule,now);
            }
        }
        if(isSyn){
            marketModule.synRoleData();
        }
    }

    /**
     * 重置玩家信息
     * 1 榷署结束后发送茶的邮件  移除榷署位置
     * 2 隔周重置榷署体力
     */
    public static boolean resetUser(NewMonopolyMarketModule marketModule){
        //当前时间，如果用这个时间，就是22点结算了
        int now = DateHelper.getCurrentSecond();
        //关引会更新，周一也要计算
        int endTime = NewMonopolyMarketCommonMgr.getResetOfficeTime((int)(marketModule.userData.getLastGuanYinRecTime()), ConfigMgr.getOfficeEndSecondNew());
        boolean isReset = false;
        synchronized(marketModule){
            //轮次可以结算了,  当前时间大于结束时间
            if(marketModule.userData.getLastGuanYinRecTime() <= endTime && endTime <= now ) {
                //先刷新结算待客茶，
                refreshOfficeTeaReward(marketModule.userData, endTime);
                sendOfficeRewardMail(marketModule);

                //结算关引（沒有用，下周体力又满了）
                refreshGuanYin(marketModule.userData, endTime, true);
                if(marketModule.userData.getOfficeCurPos() > 0){
                    //榷署每周重置
                    AutoLogMgr.add(new NewMonopolyMarketOfficeUserSeatLogData(marketModule.getUserId(), marketModule.userData.getWeekId(), marketModule.userData.getOfficeCurPos(), 0, marketModule.userData.getOfficeLevel(),
                        marketModule.userData.getOfficeNo(),0, marketModule.userData.getGuanYin() ,marketModule.userData.getOfficeSeatTime()));
                }
                //跨服也会重置，注意重置前，一定要把该结算的都结算了,所以周日22点后登录要先同步跨服数据，在线跨过22点的不能再调用该操作（由跨服结算榷署来通知）
                resetOfficeSeat(marketModule);

                marketModule.userData.setLastGuanYinRecTime(now);
                marketModule.userData.setOfficeRobTimes(0);
                marketModule.userData.setDailyOfficeResetTime(now);
                isReset = true;
            }
            marketModule.resetWeekUserData();
        }
        return isReset;
    }

    /**
     * 发送待客茶道具
     */
    public static void sendOfficeRewardMail(NewMonopolyMarketModule marketModule){
        if(marketModule.userData.getTeaLastNum() > 0){
            Property property = new Property(GameConfig.NEWMONOPOLYMARKET_GUEST_TEA_ID, BigInteger.valueOf(marketModule.userData.getTeaLastNum()));
            String language = UserMgr.getLanguage(marketModule.userData.getUserId());
            String mailTitle = MultipleLanguageMgr.getContent(MailManager.MONOPOLY_MARKET_OFFICE_REWARD_TITLE, language);
            String mailContent = MultipleLanguageMgr.getContent(MailManager.MONOPOLY_MARKET_OFFICE_REWARD_CONTENT, language);
            mailContent = StringUtils.format(mailContent, marketModule.userData.getTeaLastNum());
            MailManager.sendMail(marketModule.userData.getUserId(), eMailType.SYSTEM.getValue(), PropertyHelper.parsePropertyToString(property), mailContent, mailTitle);
            marketModule.userData.setTeaLastNum(0);
            //发送待客茶后，时间重置，下周占座再设置
            marketModule.userData.setTeaLastGetTime(0);
        }
    }

    /**
     * 每日重置榷署抢夺次数
     * @param marketModule
     * @param time
     */
    public static void resetRobTimes(NewMonopolyMarketModule marketModule, int time){
        if(DateHelper.getDiffDayNum(marketModule.userData.getDailyOfficeResetTime()) != 0 ){
            // 每日重置
            marketModule.userData.setOfficeRobTimes(0);
            marketModule.userData.setDailyOfficeResetTime(time);
        }
    }

    /**
     * 每日重置资源点派遣、搜索结果、待派遣中间状态
     * @param marketModule
     */
    private static void resetResGrabDispatch(NewMonopolyMarketModule marketModule, int time){
        if(DateHelper.getDiffDayNum(marketModule.userData.getDailyResGrabResetTime()) != 0){
            // 每日重置
            marketModule.getCurDispatchInfoListMap().clear();
            marketModule.userData.getSearchPointMap().clear();
            marketModule.userData.setWaitDispatchPoint(null);
            marketModule.userData.setDailyResGrabResetTime(time);
        }
    }

    /**
     * 刷新关引产出
     * @param userData 玩家数据
     * @param endTime 结算时间
     * @param forceUpdate 是否强制刷新
     */
    public static void refreshGuanYin(NewMonopolyMarketUserData userData, int endTime, boolean forceUpdate){
        // 刷新体力
        long diffTime = endTime - userData.getLastGuanYinRecTime();
        int maxLimit = calGuanYinMaxLimit(userData);
        if (userData.getGuanYin() < maxLimit) {
            long oldValue = userData.getGuanYin();

            int timesCD = (int)(diffTime / GameConfig.NEWMONOPOLYMARKET_REWARD_CD_1);
            if (timesCD > 0 ) {
                int productionRate = calOfficeSeatProductionRate(userData);
                int times = timesCD * productionRate;
                if (times + userData.getGuanYin() < maxLimit) {
                    userData.setLastGuanYinRecTime(userData.getLastGuanYinRecTime() + timesCD * GameConfig.NEWMONOPOLYMARKET_REWARD_CD_1);
                    userData.setGuanYin(userData.getGuanYin() + times);
                }else {
                    userData.setLastGuanYinRecTime(endTime);
                    userData.setGuanYin(maxLimit);
                }
            }
            if(oldValue != userData.getGuanYin()){
                AutoLogMgr.add(new NewMonopolyMarketUserPhysicalChangeLogData(userData.getUserId(), userData.getWeekId(), userData.getOfficeCurPos(), userData.getOfficeLevel(),
                        userData.getOfficeNo(), 5, oldValue, userData.getGuanYin()));
            }
        } else {
            if (forceUpdate) {
                if(endTime > userData.getLastGuanYinRecTime()) {
                    userData.setLastGuanYinRecTime(endTime);
                }
            }
        }
    }

    /**
     * 刷新玩家待客茶数量（位置变化前、周日22点结算、正常交互：类似定时刷新CD结算）
     * @param userData 玩家数据
     * @param now 需要计算的时间节点
     */
    public static void refreshOfficeTeaReward(NewMonopolyMarketUserData userData, int now){
        if(userData.getOfficeCurPos() >= 0 && userData.getTeaLastGetTime() > 0){
            refreshOfficeTeaReward(userData, now, userData.getOfficeNo(), userData.getOfficeLevel());
        }
    }

    public static void refreshOfficeTeaReward(NewMonopolyMarketUserData userData, int endTime, int officeNo, int officeLevel) {
        NewMonopolyMarketResConfigData configData = NewMonopolyMarketMgr.getMonopolyMarketResConfigData(eMonopolyMarketResType.OFFICE_NEW.getValue(), officeLevel);
        if(configData == null){
            return;
        }
        //改成与区服數量无关
        int rate = NewMonopolyMarketCommonMgr.calResRate(0,
                configData.rewardValue2,
                configData.rewardAdd2,
                configData.getId(),
                officeNo);
        //重要
        //不能减0
        if(userData.getTeaLastGetTime() <= 0){
            return;
        }
        int diff = endTime - userData.getTeaLastGetTime();
        int i = diff / GameConfig.NEWMONOPOLYMARKET_REWARD_CD_1;
        if(i > 0 ){
            int rewardNum = i * rate;
            userData.setTeaLastNum(userData.getTeaLastNum() + rewardNum);
            userData.setTeaLastGetTime(userData.getTeaLastGetTime() + i * GameConfig.NEWMONOPOLYMARKET_REWARD_CD_1);
        }
    }

    /**
     * 计算玩家的产出速度
     * @return
     */
    public static int calOfficeSeatProductionRate(NewMonopolyMarketUserData userData){
//        int weedId = userData.getWeekId();
//        SystemServerGroupWeekData groupWeekData = CrossSystemGroupMgr.getSystemServerGroup(weedId, eSystemId.NewMonopolyMarket.getValue());
        //改成与区服數量无关
        if(userData.getOfficeCurPos() >= 0){
            NewMonopolyMarketResConfigData configData = NewMonopolyMarketMgr.getMonopolyMarketResConfigData(eMonopolyMarketResType.OFFICE_NEW.getValue(), userData.getOfficeLevel());
            return NewMonopolyMarketCommonMgr.calResRate(0,
                    configData.rewardValue1, configData.rewardAdd1,
                    configData.getId(),
                    userData.getOfficeNo());
        }
        return GameConfig.NEWMONOPOLYMARKET_INITIAL_GUANYIN_SPEED;
    }

    /**
     * 计算玩家体力上限
     * @return
     */
    public static int calGuanYinMaxLimit(NewMonopolyMarketUserData userData){
        if(userData.getOfficeLevel() > 0){
            NewMonopolyMarketResConfigData configData = NewMonopolyMarketMgr.getMonopolyMarketResConfigData(eMonopolyMarketResType.OFFICE_NEW.getValue(), userData.getOfficeLevel());
            if(configData != null){
                return configData.getLimit();
            }
        }
        return GameConfig.NEWMONOPOLYMARKET_INITIAL_GUANYIN_MAX;
    }

    /**
     * 重置榷署位置
     * @param marketModule
     */
    public static void resetOfficeSeat(NewMonopolyMarketModule marketModule){
        marketModule.userData.setOfficeCurPos(-1);
        marketModule.userData.setOfficeSeatTime(0);
        marketModule.userData.setOfficeLevel(0);
        marketModule.userData.setOfficeNo(0);
        marketModule.userData.setOfficeTip(null);
        //沒有位置就沒有起始时间
        marketModule.userData.setTeaLastGetTime(0);
    }

    /**
     * 榷署入座
     * @param marketModule
     * @param seatInfo
     * @param level
     * @param no
     */
    public static void sitOffice(NewMonopolyMarketModule marketModule, NewMonopolyMarketProto.NewMonopolyMarketOfficeEntity seatInfo, int level, int no){
        marketModule.userData.setOfficeCurPos(seatInfo.getPosIndex());
        marketModule.userData.setOfficeSeatTime((int)(seatInfo.getSeatTime()));
        marketModule.userData.setOfficeLevel(level);
        marketModule.userData.setOfficeNo(no);
        marketModule.userData.setTeaLastGetTime((int)(seatInfo.getSeatTime()));
    }

    /**
     * 计算入座需要消耗多少元宝
     * @return
     */
    public static int calSitDownConsumeGold(NewMonopolyMarketUserData userData){
        if(userData.getOfficeRobTimes() < GameConfig.NEWMONOPOLYMARKET_FREESEIZE_1){
            return 0;
        }
        int diffTimes = userData.getOfficeRobTimes() - GameConfig.NEWMONOPOLYMARKET_FREESEIZE_1;
        return Math.min(diffTimes * ConfigMgr.getOfficeConsumeNew().addConsume + ConfigMgr.getOfficeConsumeNew().initConsume, ConfigMgr.getOfficeConsumeNew().maxConsume);
    }

    /**
     * 加榷署战报
     * @param player 有可能为空
     * @param msg
     */
    public static void addReport(GamePlayer player,NewMonopolyMarketProto.NewMonopolyMarketSynAttackToGameServerMsg msg){
        UserBaseInfo attackInfo = null;
        if(!msg.hasAttackInfo()) {
            attackInfo = UserMgr.getUserBaseInfo(msg.getAttackId(), GameServer.getInstance().getServerId());
        }else {
            attackInfo = PlayerBasePb.parseToUserBaseInfo(msg.getAttackInfo());
        }
        NewMonopolyMarketReportData report = new NewMonopolyMarketReportData();
        report.setType(msg.getType());
        report.setUserId(msg.getRobedId());
        report.setIsWin(msg.getIsWin());
        report.setPosIndex(msg.getPosIndex());
        report.setRobId(msg.getAttackId());
        report.setRobInfo(attackInfo);
        report.setResGroupId(msg.getResGroupId());
        report.setWeekId(msg.getWeekId());
        report.setTime(DateHelper.getCurrentSecond());
        report.setActionType(msg.getRobType());
        report.setInsertOption();
        NewMonopolyMarketModule marketModule = null;
        if(player != null){
            marketModule = player.getModule(NewMonopolyMarketModule.class);
            if(msg.getType() == eMonopolyMarketResType.OFFICE_NEW.getValue()){
                synchronized (marketModule.officeReportList){
                    while (marketModule.officeReportList.size() >= GameConfig.NEWMONOPOLYMARKET_KEEPINFO_1){
                        marketModule.officeReportList.remove(0);
                    }
                    marketModule.officeReportList.add(report);
                }
                // 去跨服结算
                if(msg.getIsWin()){
                    marketModule.userData.setHasTip(true);
                    NewMonopolyMarketMgr.sendAppointActivityPacket(player.getUserId(), CrossProtocol.C_CROSS_NEW_MONOPOLY_MARKET_GET_USER_DATA, CommonProto.NullValueMsg.newBuilder());
                }
            }else {
                synchronized (marketModule.resGrabReportList){
                    while (marketModule.resGrabReportList.size() >= GameConfig.NEWMONOPOLYMARKET_KEEPINFO_2){
                        marketModule.resGrabReportList.remove(0);
                    }
                    marketModule.resGrabReportList.add(report);
                }
                if(msg.getIsWin()){
                    marketModule.userData.setHasTip(true);
                    leaveResGrabPoint(player, msg.getResGroupId(), msg.getPosIndex(),false);
                    if(marketModule.getInSystemId() >= 0){
                        // 去跨服领取奖励
                        NewMonopolyMarketMgr.sendAppointActivityPacket(player.getUserId(), CrossProtocol.C_CROSS_NEW_MONOPOLY_MARKET_RES_GRAB_RECEIVE_REWARD, CommonProto.NullValueMsg.newBuilder());
                    }
                }
            }
        }else {
            new NewMonopolyMarketReportDataDaoImpl().add(report);
        }
        if(msg.getIsWin()){
            String mailTitle = null;
            String mailContent = null;
            String language = UserMgr.getLanguage(msg.getRobedId());
            String serverName = ServerListMgr.getServerName(attackInfo.getServerId(),language);
            if(msg.getType() == eMonopolyMarketResType.OFFICE_NEW.getValue()){
                NewMonopolyMarketResConfigData configData = NewMonopolyMarketMgr.getMonopolyMarketResConfigData(eMonopolyMarketResType.OFFICE_NEW.getValue(), msg.getLevel());
                String MONOPOLYMARKET_NAME = "NEWMONOPOLYMARKET_NAME_" + configData.getMonster();
                // 加邮件通知 强夺者区服|强夺者名字|level|no
                mailTitle = MultipleLanguageMgr.getContent(MailManager.MONOPOLY_MARKET_OFFICE_ROBBED_TITLE, language);
                mailContent = MultipleLanguageMgr.getContent(MailManager.MONOPOLY_MARKET_OFFICE_ROBBED_CONTENT, language);
                String posName = MultipleLanguageMgr.getContent(MONOPOLYMARKET_NAME, language);
                mailContent = StringUtils.format(mailContent, serverName,attackInfo.getNickName(),posName,msg.getNo());

            }else {
                // 加邮件通知 强夺者区服|强夺者名字|type|level|x|y
                mailTitle = MultipleLanguageMgr.getContent(MailManager.MONOPOLY_MARKET_RES_GRAB_ROBBED_TITLE, language);
                mailContent = MultipleLanguageMgr.getContent(MailManager.MONOPOLY_MARKET_RES_GRAB_ROBBED_CONTENT, language);
                String MONOPOLYMARKET_RESOURCE_NAME = "NEWMONOPOLYMARKET_RESOURCE_NAME_" + msg.getType();
                MONOPOLYMARKET_RESOURCE_NAME = MultipleLanguageMgr.getContent(MONOPOLYMARKET_RESOURCE_NAME, language);
                mailContent = StringUtils.format(mailContent, serverName,attackInfo.getNickName(),MONOPOLYMARKET_RESOURCE_NAME,msg.getLevel(),msg.getX(),msg.getY());
            }
            MailManager.sendMail(msg.getRobedId(), eMailType.SYSTEM.getValue(), "",mailContent,mailTitle);
        }
    }

    /**
     * 校验今日是否可以再派遣
     * @param type
     * @param todayTimes
     * @return
     */
    public static int checkTodayDispatchTimes(int type, int todayTimes){
        if(type == eMonopolyMarketResType.OFFICE_NEW.getValue()){
            if(todayTimes - GameConfig.NEWMONOPOLYMARKET_FREESEIZE_1 >= GameConfig.NEWMONOPOLYMARKET_SEIZE_MAX_1){
                return GameErrorCode.E_NEW_MONOPOLY_MARKET_DISPATCH_LIMIT_HAS_BEEN_REACHED;
            }
        }
        return 0;
    }

    /**
     * 检查派遣数量
     * @param type
     * @param dispatchNum
     * @return
     */
    public static int checkDispatchNum(int type,int dispatchNum){
        if(type == eMonopolyMarketResType.RES_KING_NEW.getValue() && dispatchNum > GameConfig.NEWMONOPOLYMARKET_TEAMLIMIT_MAX_2){
            return GameErrorCode.E_NEW_MONOPOLY_MARKET_RES_GRAB_NO_OBJECT;
        }
        if(type == eMonopolyMarketResType.RES_QUEEN_NEW.getValue() && dispatchNum > GameConfig.NEWMONOPOLYMARKET_TEAMLIMIT_MAX_3){
            return GameErrorCode.E_NEW_MONOPOLY_MARKET_RES_GRAB_NO_OBJECT;
        }
        return 0;
    }

    /**
     * 检查派遣队伍数量
     * @param player
     * @param type
     * @return
     */
    public static int checkTeamNum(GamePlayer player, int type){
        NewMonopolyMarketModule marketModule = player.getModule(NewMonopolyMarketModule.class);
        List<Set<NewMonopolyMarketResGrabDispatchInfo>> list = marketModule.getCurDispatchInfoListMap(type);
        if(type == eMonopolyMarketResType.RES_KING_NEW.getValue() && list.size() >= GameConfig.NEWMONOPOLYMARKET_ARMYLIMIT_2){
            return GameErrorCode.E_NEW_MONOPOLY_MARKET_RES_GRAB_TEAM_LIMIT_HAS_BEEN_REACHED;
        }
        if(type == eMonopolyMarketResType.RES_QUEEN_NEW.getValue() && list.size() >= GameConfig.NEWMONOPOLYMARKET_ARMYLIMIT_3){
            return GameErrorCode.E_NEW_MONOPOLY_MARKET_RES_GRAB_TEAM_LIMIT_HAS_BEEN_REACHED;
        }
        return 0;
    }

    /**
     * 撤回据点
     * @param player
     * @param resGroupId
     * @param posIndex
     */
    public static void leaveResGrabPoint(GamePlayer player,int resGroupId, int posIndex,boolean isSyn){
        NewMonopolyMarketModule marketModule = player.getModule(NewMonopolyMarketModule.class);
        Map<Integer, Set<NewMonopolyMarketResGrabDispatchInfo>> map = marketModule.getCurDispatchInfoListMap(resGroupId,true);
        map.remove(posIndex);
        if(isSyn){
            player.getModule(NewMonopolyMarketModule.class).synRoleData();
        }
    }

    /**
     * 发送到活动跨服
     */
    public static void sendAppointActivityPacket(long playerId, int code, AbstractMessage.Builder<?> messageBuilder) {
        CrossSystemGroupMgr.sendAppointActivityPacket(playerId, code, eSystemId.NewMonopolyMarket.getValue(), messageBuilder);
    }

    /**
     * 榷场更新门客信息
     * @param player
     * @param patronsList
     */
    public static void synPatronsAbility(GamePlayer player,List<UserPatrons> patronsList){
        for (UserPatrons item : patronsList){
            addNeedUploadObjectInfo(player,eMonopolyMarketResType.RES_KING_NEW.getValue(),item.getPatronsId());
        }
    }

    /**
     * @param type
     * @param rewardNum
     * @return
     */
    public static Property addReward(int type, int rewardNum){
        Property property = new Property();
        int goods = NewMonopolyMarketCommonMgr.getGoodsId(type);
        property.addProperty(goods, BigInteger.valueOf(rewardNum));
        return property;
    }

    public static void uploadUserInfo(){
        List<Long> list = new ArrayList<>();
        synchronized (needUploadUserInfoSet) {
            for (long userId : needUploadUserInfoSet){
                list.add(userId);
            }
            needUploadUserInfoSet.clear();
        }
        if(list.size() > 0){
            for (long uid : list) {
                GamePlayer player = GamePlayerMgr.getOnlinePlayer(uid);
                if(player != null){
                    player.getModule(NewMonopolyMarketModule.class).syncPlayerBaseInfoToCross();
                }
            }
        }
    }

    public static void addNeedUploadUserInfo(GamePlayer player){
        //玩家是否有解锁
        if(!canEnterSystem(player)){
            return;
        }
        synchronized (needUploadUserInfoSet){
            needUploadUserInfoSet.add(player.getUserId());
        }
    }

    /**
     * 门客、美女变更
     * @param player
     * @param type
     * @param objectId
     */
    public static void addNeedUploadObjectInfo(GamePlayer player,int type, Integer objectId){
        if(!canEnterSystem(player)){
            return;
        }
        if(!isSystemOpenTime(type)){
            return;
        }

        synchronized (needUploadObjectInfoMap){
            ConcurrentHashMap<Integer,Set<Integer>> map = needUploadObjectInfoMap.get(player.getUserId());
            if(map == null){
                map = new ConcurrentHashMap<>();
                needUploadObjectInfoMap.put(player.getUserId(),map);
            }
            Set set = map.get(type);
            if(set == null){
                set = new HashSet();
                map.put(type,set);
            }
            set.add(objectId);
        }
    }

    public static void uploadObjectInfo(){
        synchronized (needUploadObjectInfoMap) {
            for (Map.Entry<Long,ConcurrentHashMap<Integer, Set<Integer>>> entry : needUploadObjectInfoMap.entrySet()){
                long userId = entry.getKey();
                GamePlayer player = GamePlayerMgr.getOnlinePlayer(userId);
                if(player == null){
                    continue;
                }
                NewMonopolyMarketProto.NewMonopolyMarketSynDispatchToCrossReqMsg.Builder synDispatch = NewMonopolyMarketProto.NewMonopolyMarketSynDispatchToCrossReqMsg.newBuilder();
                //type,objectList
                ConcurrentHashMap<Integer, Set<Integer>> map = entry.getValue();

                NewMonopolyMarketModule marketModule = player.getModule(NewMonopolyMarketModule.class);

                //更新所有门客
                boolean updateAllPatrons = false;
                //更新所有派遣的美女
                boolean updateAllBeauty = false;
                if(map.containsKey(eMonopolyMarketResType.RES_KING_NEW.getValue())){
                    updateAllPatrons = PatronsMgr.hasSkillType(player,new ArrayList<>(map.get(eMonopolyMarketResType.RES_KING_NEW.getValue())), eSkillType.CALABASH_BROTHERS_KING.getValue());
                    updateAllBeauty = PatronsMgr.hasSkillType(player,new ArrayList<>(map.get(eMonopolyMarketResType.RES_KING_NEW.getValue())), eSkillType.CALABASH_BROTHERS_QUEEN.getValue());
                }

                for (Map.Entry<Integer,Set<Integer>> item : map.entrySet()) {
                    //门客或者美女
                    int type = item.getKey();

                    Set<Integer> set = item.getValue();

                    //门客变更
                    if (type == eMonopolyMarketResType.RES_KING_NEW.getValue()) {

                        if (updateAllPatrons) {
                            List<Set<NewMonopolyMarketResGrabDispatchInfo>> dispatchInfoList = marketModule.getCurDispatchInfoListMap(eMonopolyMarketResType.RES_KING_NEW.getValue());
                            for (Set<NewMonopolyMarketResGrabDispatchInfo> dispatchInfos : dispatchInfoList) {
                                List<UserPatrons> patronsList = getDispatchPatronsList(player, dispatchInfos);
                                for (NewMonopolyMarketResGrabDispatchInfo dispatchInfo : dispatchInfos) {
                                    // 同步有变化的门客
                                    UserPatrons patrons = player.getModule(PatronsModule.class).getUserPatrons(dispatchInfo.getDispatchId());
                                    synDispatch.addResGrabPatronsList(builderMonopolyMarketPatronsEntity(player, patrons, patronsList).build());
                                }
                            }
                        } else {

                            List<Set<NewMonopolyMarketResGrabDispatchInfo>> dispatchInfoList = marketModule.getCurDispatchInfoListMap(eMonopolyMarketResType.RES_KING_NEW.getValue());
                            for (Set<NewMonopolyMarketResGrabDispatchInfo> dispatchInfos : dispatchInfoList) {
                                boolean add = false;
                                for (NewMonopolyMarketResGrabDispatchInfo dispatchInfo : dispatchInfos) {
                                    // 同步有变化的门客
                                    if (set.contains(dispatchInfo.getDispatchId())) {
                                        add = true;
                                        break;
                                    }
                                }
                                if (add) {
                                    List<UserPatrons> patronsList = getDispatchPatronsList(player, dispatchInfos);
                                    for (NewMonopolyMarketResGrabDispatchInfo dispatchInfo : dispatchInfos) {
                                        // 同步有变化的门客
                                        UserPatrons patrons = player.getModule(PatronsModule.class).getUserPatrons(dispatchInfo.getDispatchId());
                                        synDispatch.addResGrabPatronsList(builderMonopolyMarketPatronsEntity(player, patrons, patronsList).build());
                                    }
                                }
                            }
                        }

                        continue;
                    }

                    //美女加成
                    int addPlus = getPatronsPlusForQueen(player);

                    if (updateAllBeauty) {
                        List<Set<NewMonopolyMarketResGrabDispatchInfo>> dispatchInfoList = marketModule.getCurDispatchInfoListMap(eMonopolyMarketResType.RES_QUEEN_NEW.getValue());
                        for (Set<NewMonopolyMarketResGrabDispatchInfo> dispatchInfos : dispatchInfoList) {
                            for (NewMonopolyMarketResGrabDispatchInfo dispatchInfo : dispatchInfos) {
                                // 同步有变化的门客
                                UserBeauty beauty = player.getModule(BeautyModule.class).getUserBeauty(dispatchInfo.getDispatchId());
                                synDispatch.addResGrabBeautyList(builderMonopolyMarketBeautyEntity(beauty, addPlus).build());
                            }
                        }
                    } else {

                        for (int objectId : set) {
                            if (marketModule.isDispatch(eMonopolyMarketResType.RES_QUEEN_NEW.getValue(), objectId)) {
                                // 同步有变化的美女
                                UserBeauty beauty = player.getModule(BeautyModule.class).getUserBeauty(objectId);
                                synDispatch.addResGrabBeautyList(builderMonopolyMarketBeautyEntity(beauty, addPlus).build());
                            }
                        }
                    }
                }

                if(synDispatch.getResGrabBeautyListCount() > 0 || synDispatch.getResGrabPatronsListCount() > 0){
                    sendAppointActivityPacket(0, CrossProtocol.C_CROSS_NEW_MONOPOLY_MARKET_SYN_DISPATCH_INFO, synDispatch);
                }
            }
            needUploadObjectInfoMap.clear();
        }
    }

    public static int getPatronsPlusForQueen(GamePlayer player){
        int addPlus = PatronsMgr.getMonopolyMarketPatronsPlus(player, eSkillType.CALABASH_BROTHERS_QUEEN.getValue());
        addPlus += (int)CurioMgr.getSkillAdditionBySkillType(eSkillType.CurioNewMonopolyBeautySkill.getValue(), player, 0);
        return addPlus;
    }

    public static int getPatronsPlusForKing(GamePlayer player){
        int addPlus = PatronsMgr.getMonopolyMarketPatronsPlus(player, eSkillType.CALABASH_BROTHERS_KING.getValue());
        addPlus += PatronsMgr.getMonopolyMarketPatronsPlus(player, eSkillType.WineryCalabashAddition.getValue());
        addPlus += (int)CurioMgr.getSkillAdditionBySkillType(eSkillType.CurioNewMonopolyPatronsSkill.getValue(), player, 0);
        return addPlus;
    }

    /**
     *
     * @param player
     * @param patrons 要计算的当前门客
     * @param list 队伍门客
     * @return
     */
    public static NewMonopolyMarketProto.NewMonopolyMarketPatronsEntity.Builder builderMonopolyMarketPatronsEntity(GamePlayer player, UserPatrons patrons, List<UserPatrons> list){
        int addPlus = 0;
        // 计算该门客的自己战斗加成
        addPlus = getAddPlus(patrons);
        PatronsInfo patronsInfo = PatronsMgr.getPatronsInfo(patrons.getPatronsId());
        // 计算同类型门客
        for(UserPatrons member : list){
            if(member.getPatronsId() == patrons.getPatronsId()){
                continue;
            }
            PatronsInfo memberPatronsInfo = PatronsMgr.getPatronsInfo(member.getPatronsId());
            if(patronsInfo.getOccupation() == memberPatronsInfo.getOccupation()){
                addPlus += getAddPlus(member);
            }
        }
        // 算葫芦娃加成
        addPlus += getPatronsPlusForKing(player);

        NewMonopolyMarketProto.NewMonopolyMarketPatronsEntity.Builder builder = NewMonopolyMarketProto.NewMonopolyMarketPatronsEntity.newBuilder();
        builder.setPatronsId(patrons.getPatronsId());
        builder.setLevel(patrons.getLevel());
        builder.setStageLv(patrons.getStageLv());
        builder.setSkinId(patrons.getSkinId());
        long earn = patrons.getAbility().longValue();
        builder.setEarn(earn);
        builder.setAddPlus(addPlus);
        builder.setPromotionId(patrons.getShowPromotionId());
        if(Config.isDebug()){
            getLogger().info("门客：{}, 基础能力 ：{}， 加成：{}", patrons.getPatronsId(), patrons.getAbility().toString(), addPlus);
        }
        return builder;
    }

    public static int getAddPlus(UserPatrons patrons){
        int addPlus = 0;
        if(patrons != null){
            for (UserPatronsSkill userPatronsSkill : patrons.getSkillList()){
                SkillInfo skillInfo = SkillMgr.getSkillInfo(userPatronsSkill.getSkillId());
                if(skillInfo == null){
                    continue;
                }
                if (skillInfo.getType() == eSkillType.BattleEffect.getValue() ) {
                    addPlus += SkillMgr.getSkillAddition(skillInfo, userPatronsSkill.getSkillLv());
                }
            }
        }
        return addPlus;
    }

    /**
     * 获取set里面的id集合
     * @param set
     * @return
     */
    public static List<UserPatrons> getDispatchPatronsList(GamePlayer player, Set<NewMonopolyMarketResGrabDispatchInfo> set){
        List<UserPatrons> patronsList = new ArrayList<>();
        for (NewMonopolyMarketResGrabDispatchInfo dispatchInfo : set){
            UserPatrons userPatrons = player.getModule(PatronsModule.class).getUserPatrons(dispatchInfo.getDispatchId());
            patronsList.add(userPatrons);
        }
        return patronsList;
    }

    @Override
    public boolean init() throws Exception {
        CrossSystemGroupMgr.addReloadListener(() -> {
            for (GamePlayer player : GamePlayerMgr.getAllOnlinePlayer()) {
                player.getModule(NewMonopolyMarketModule.class).initSystem();
            }
        });
        return reload();
    }

    @Override
    public boolean reloadConfig() throws Exception {
        resConfigList = NewMonopolyMarketBussiness.getMonopolyMarketResConfigDataList();
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    @Override
    public boolean stop() {
        return false;
    }

    public static List<NewMonopolyMarketResConfigData> getResConfigListByType(int type){
        List<NewMonopolyMarketResConfigData> result = new ArrayList<>();
        for (NewMonopolyMarketResConfigData configData : resConfigList) {
            if(configData.getType() == type){
                result.add(configData);
            }
        }
        return result;
    }

    public static NewMonopolyMarketResConfigData getMonopolyMarketResConfigData(int type, int lv){
        for (NewMonopolyMarketResConfigData configData : resConfigList) {
            if(configData.getType() == type && configData.getLevel() == lv){
                return configData;
            }
        }
        return null;
    }

    public static void fetchWeekStateData(){
        int weekId = GameConfig.getSystemThisWeekId();
        if(!weekResourceGroupMap.containsKey(weekId)){
            NewMonopolyMarketProto.NewMonopolyMarketInnerGroupReqMsg.Builder builder = NewMonopolyMarketProto.NewMonopolyMarketInnerGroupReqMsg.newBuilder();
            builder.setWeekId(weekId);
            sendAppointActivityPacket(0, Protocol.C_CROSS_NEW_MONOPOLY_MARKET_SYNC_INNER_GROUP, builder);
        }
    }

    /**
     * 上传活跃玩家的6队门客、美女队伍能力
     * 队伍随机组合
     * 每周上报一次
     */
    public static void uploadTodayServerUserAbility(){
        int weekId = GameConfig.getSystemThisWeekId();
        if(!weekResourceGroupMap.containsKey(weekId)){
            return;
        }
        if(!inActivePeriod(eSystemId.NewMonopolyMarket.getValue())){
            return;
        }
        int zeroTime = DateHelper.getTodayZeroTime();

        //活跃天数
        int activeDay = GameConfig.NEWMONOPOLYMARKET_RESOURCE_PARAM_3;
        //每队门客数
        int patronsNumPerTeam = GameConfig.NEWMONOPOLYMARKET_TEAMLIMIT_MAX_2;
        //没队美女数
        int beautyNumPerTeam = GameConfig.NEWMONOPOLYMARKET_TEAMLIMIT_MAX_3;
        //上报队伍上限
        int topTeamNum = GameConfig.NEWMONOPOLYMARKET_BLOOD_PARAM;

        List<UserInfo> list = UserMgr.getUserInfoList();
        //活动开始3天内有登录过的
        list.removeIf(userInfo -> userInfo.getLastLoginTime() < zeroTime - activeDay * DateHelper.DAY_SECONDS);

        NewMonopolyMarketProto.NewMonopolyMarketUploadAbilityMsg.Builder upload = NewMonopolyMarketProto.NewMonopolyMarketUploadAbilityMsg.newBuilder();
        upload.setZeroTime(zeroTime);
        if(list.size() > 0){
            Random random = new Random();
            for (UserInfo userInfo : list) {
                NewMonopolyMarketProto.NewMonopolyMarketUserAbilityTemp.Builder builder = NewMonopolyMarketProto.NewMonopolyMarketUserAbilityTemp.newBuilder();
                builder.setUserId(userInfo.getUserId());

                //门客
                List<UserPatronsSimple> patronsSimpleList = PatronsSimpleCacheMgr.getUserPatronsSimpleList(userInfo.getUserId());
                if(patronsSimpleList != null){
                    int teamNum = patronsSimpleList.size() / patronsNumPerTeam;
                    if(teamNum > topTeamNum){
                        teamNum = topTeamNum;
                    }
                    int totalNum = teamNum * patronsNumPerTeam;
                    List<Long> abilityList = new ArrayList<>();
                    patronsSimpleList.sort((o1, o2) -> o2.getAbility().compareTo(o1.getAbility()));
                    for (int i = 0; i < patronsSimpleList.size() && i < totalNum; i++) {
                        abilityList.add(patronsSimpleList.get(i).getAbility().longValue());
                    }

                    if(Config.isDebug()){
                        //测试环境，顺序组队
                        long ability = 0;
                        for (int i = 0; i < abilityList.size(); i++) {
                            ability += abilityList.get(i);
                            if((i + 1) % teamNum == 0){
                                builder.addPatronsAbility(ability);
                                ability = 0;
                            }
                        }
                    }else {
                        //随机分队
                        long ability = 0;
                        int i = 0;
                        while (abilityList.size() > 0){
                            ability += abilityList.remove(random.nextInt(abilityList.size()));
                            i++;
                            if(i == patronsNumPerTeam){
                                i = 0;
                                builder.addPatronsAbility(ability);
                                ability = 0;
                            }
                        }
                    }
                }

                //美女
                GamePlayer gamePlayer = GamePlayerMgr.getOnlinePlayer(userInfo.getUserId());
                List<UserBeauty> beautyList;
                if(gamePlayer != null){
                    beautyList = new ArrayList<>(gamePlayer.getModule(BeautyModule.class).getBeautyMap().values());
                }else {
                    beautyList = new ArrayList<>(UserBeautyBussiness.getUserBeautyMap(userInfo.getUserId()).values());
                }
                beautyList.sort((o1, o2) -> Integer.compare(o2.getTotalGlamour(), o1.getTotalGlamour()));

                int teamNum = beautyList.size() / beautyNumPerTeam;
                if(teamNum > topTeamNum){
                    teamNum = topTeamNum;
                }
                int totalNum = teamNum * beautyNumPerTeam;
                List<Integer> abilityList = new ArrayList<>();
                for (int i = 0; i < beautyList.size() && i < totalNum; i++) {
                    abilityList.add(beautyList.get(i).getTotalGlamour());
                }

                if(Config.isDebug()){
                    //测试环境，顺序组队
                    long ability = 0;
                    for (int i = 0; i < abilityList.size(); i++) {
                        ability += abilityList.get(i);
                        if((i + 1) % teamNum == 0){
                            builder.addBeautyAbility(ability);
                            ability = 0;
                        }
                    }
                }else {
                    //随机分队
                    long ability = 0;
                    int i = 0;
                    while (abilityList.size() > 0) {
                        ability += abilityList.remove(random.nextInt(abilityList.size()));
                        i++;
                        if (i == beautyNumPerTeam) {
                            i = 0;
                            builder.addBeautyAbility(ability);
                            ability = 0;
                        }
                    }
                }

                if(builder.getBeautyAbilityCount() == 0 || builder.getPatronsAbilityCount() == 0){
                    getLogger().info("weekId {} monopoly market active num skip {}", weekId, builder.getUserId());
                    continue;
                }
                upload.addAbility(builder);
            }
            sendAppointActivityPacket(0, Protocol.C_CROSS_NEW_MONOPOLY_MARKET_UPLOAD_SERVER_ABILITY, upload);
            getLogger().info("weekId {} monopoly market active num {}", weekId, upload.getAbilityCount());
        }else {
            sendAppointActivityPacket(0, Protocol.C_CROSS_NEW_MONOPOLY_MARKET_UPLOAD_SERVER_ABILITY, upload);
        }
    }


    /**
     * 系统期间
     * @param systemId 系统id
     */
    public static boolean inActivePeriod(int systemId){
        Calendar calendar = Calendar.getInstance();
        //if(Config.isDebug()){
        //    return true;
        //}
        int day = calendar.get(Calendar.DAY_OF_WEEK);
        return day == Calendar.FRIDAY || day == Calendar.SUNDAY || day == Calendar.SATURDAY;
    }

    public static void offLine(GamePlayer player){
        if(canEnterSystem(player)){
            NewMonopolyMarketModule marketModule = player.getModule(NewMonopolyMarketModule.class);
            if(marketModule.getInSystemId() < 0){
                return;
            }
            marketModule.changeInSystemId(-1);
            NewMonopolyMarketProto.NewMonopolyMarketExitReqMsg.Builder builder = NewMonopolyMarketProto.NewMonopolyMarketExitReqMsg.newBuilder();
            builder.setIsOffOnline(true);
            exit(player,builder);
        }
    }

    //--------

    public static List<NewMonopolyMarketResConfigData> getResConfigList() {
        return resConfigList;
    }

    public static Map<Integer, NewMonopolyMarketResGrabMap> getResGrabMapMap() {
        return resGrabMapMap;
    }

    public static void setResGrabMapMap(Map<Integer, NewMonopolyMarketResGrabMap> resGrabMapMap) {
        NewMonopolyMarketMgr.resGrabMapMap = resGrabMapMap;
    }

    public static void exit(GamePlayer player, NewMonopolyMarketProto.NewMonopolyMarketExitReqMsg.Builder builder){
        NewMonopolyMarketMgr.sendAppointActivityPacket(player.getUserId(), Protocol.C_CROSS_NEW_MONOPOLY_MARKET_EXIT, builder);
    }

    public static NewMonopolyMarketProto.NewMonopolyMarketOfficeReportEntity.Builder builderMonopolyMarketOfficeReportEntity(NewMonopolyMarketReportData reportData){
        NewMonopolyMarketProto.NewMonopolyMarketOfficeReportEntity.Builder builder = NewMonopolyMarketProto.NewMonopolyMarketOfficeReportEntity.newBuilder();
        builder.setType(reportData.getType());
        builder.setRobId(reportData.getRobId());
        builder.setRobInfo(PlayerBasePb.parsePlayerBaseTempMsg(reportData.getRobInfo()));
        builder.setPosIndex(reportData.getPosIndex());
        builder.setIsWin(reportData.getIsWin());
        builder.setTime(reportData.getTime());
        builder.setActionType(reportData.getActionType());
        builder.setResGroupId(reportData.getResGroupId());
        return builder;
    }

    public static NewMonopolyMarketProto.NewMonopolyMarketResGrabTipEntity.Builder builderMonopolyMarketResGrabTipEntity(NewMonopolyMarketProto.NewMonopolyMarketSynPointSettlementToGameServerMsg msg){
        NewMonopolyMarketProto.NewMonopolyMarketResGrabTipEntity.Builder tipBuilder = NewMonopolyMarketProto.NewMonopolyMarketResGrabTipEntity.newBuilder();
        tipBuilder.setType(msg.getType());
        tipBuilder.setPosIndex(msg.getPosIndex());
        tipBuilder.setSide(msg.getSide());
        tipBuilder.setLevel(msg.getLevel());
        tipBuilder.setTotalTime(msg.getRewardTime());
        tipBuilder.setRobName(msg.getRobName());
        tipBuilder.addAllObjectList(msg.getDispatchObjectIdList());
        tipBuilder.setRewardNum(msg.getRewardNum());
        tipBuilder.setBuffValues(msg.getBuffValues());
        tipBuilder.setTotalRewardNum(msg.getTotalRewardNum());
        tipBuilder.setResGroupId(msg.getResGroupId());
        return tipBuilder;
    }

    public static NewMonopolyMarketProto.NewMonopolyMarketUserEntity.Builder builderMonopolyMarketUserEntity(NewMonopolyMarketModule marketModule){
        NewMonopolyMarketProto.NewMonopolyMarketUserEntity.Builder builder = NewMonopolyMarketProto.NewMonopolyMarketUserEntity.newBuilder();
        builder.setUserId(marketModule.userData.getUserId());
        builder.setPhysical(marketModule.userData.getGuanYin());
        builder.setRefreshTime(marketModule.userData.getLastGuanYinRecTime());
        builder.setOfficeLevel(marketModule.userData.getOfficeLevel());
        builder.setOfficeSeatTime(marketModule.userData.getOfficeSeatTime());
        builder.setOfficeCurPosIndex(marketModule.userData.getOfficeCurPos());
        builder.setOfficeRobTimes(marketModule.userData.getOfficeRobTimes());
        builder.setUserId(marketModule.userData.getUserId());
        builder.setDailyRefreshTime(marketModule.userData.getDailyOfficeResetTime());
        builder.setHasTip(marketModule.userData.isHasTip());
        builder.setTeaLastNum(marketModule.userData.getTeaLastNum());
        builder.setTeaLastGetTime(marketModule.userData.getTeaLastGetTime());
        if(marketModule.officeReportList.size() > 0){
            builder.setHasNewOfficeReport(marketModule.userData.getEnterOfficeReportLastTime() < marketModule.officeReportList.get(marketModule.officeReportList.size() - 1).getTime());
        }
        if(marketModule.resGrabReportList.size() > 0){
            builder.setHasNewResGrabReport(marketModule.userData.getEnterResGrabReportLastTime() < marketModule.resGrabReportList.get(marketModule.resGrabReportList.size() - 1).getTime());
        }
        //如果是周一,去掉战报红点
        if(NewMonopolyMarketCommonMgr.inWeekRewardTime((int)marketModule.userData.getLastGuanYinRecTime(), DateHelper.getCurrentSecond())){
            builder.setHasNewOfficeReport(false);
            builder.setHasNewResGrabReport(false);
        }

        for (Map.Entry<Integer, NewMonopolyMarketTempPoint> pointEntry : marketModule.userData.getSearchPointMap().entrySet()) {
            NewMonopolyMarketProto.NewMonopolyMarketResSearchResultTemp.Builder searchBuilder = NewMonopolyMarketProto.NewMonopolyMarketResSearchResultTemp.newBuilder();
            searchBuilder.setPosIndex(pointEntry.getValue().getPosIndex());
            searchBuilder.setResGroupId(pointEntry.getValue().getResGroupId());
            builder.addSearch(searchBuilder);
        }
        builder.setGetServerReward(marketModule.userData.isGetServerReward());
        builder.setGetUserReward(marketModule.userData.isGetUserReward());
        return builder;
    }

    public static NewMonopolyMarketProto.NewMonopolyMarketResGrabDispatchTimesEntity.Builder builderMonopolyMarketResGrabDispatchTimesEntity(NewMonopolyMarketResGrabDispatchInfo item){
        NewMonopolyMarketProto.NewMonopolyMarketResGrabDispatchTimesEntity.Builder builder = NewMonopolyMarketProto.NewMonopolyMarketResGrabDispatchTimesEntity.newBuilder();
        builder.setId(item.getDispatchId());
        builder.setPosIndex(item.getPosIndex());
        builder.setSeatTime(item.getSeatTime());
        builder.setResGroupId(item.getResGroupId());
        return builder;
    }

    public static NewMonopolyMarketProto.NewMonopolyMarketBeautyEntity.Builder builderMonopolyMarketBeautyEntity(UserBeauty beauty,int addPlus){
        NewMonopolyMarketProto.NewMonopolyMarketBeautyEntity.Builder builder = NewMonopolyMarketProto.NewMonopolyMarketBeautyEntity.newBuilder();
        builder.setAddPlus(addPlus);
        builder.setId(beauty.getBeautyId());
        builder.setSkinId(beauty.getSkinId());
        builder.setValue(beauty.getTotalGlamour());
        return builder;
    }
}
